package com.ybkj.o2o.sales.controller.res;



import com.ybkj.o2o.sales.common.transport.Error;
import com.ybkj.o2o.sales.common.transport.Result;
import com.ybkj.o2o.sales.entity.ActivityCouponRule;
import com.ybkj.o2o.sales.manager.ActivityCouponRuleManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping(value = "api/activityRule")
public class ActivityCouponRuleRes {
  @Autowired
  private ActivityCouponRuleManager activityCouponRuleManager;



  /**
   * 根据id查询活动所有优惠券规则.
   * 
   * @param activityId 活动id
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "findByActivityId", method = RequestMethod.GET)
  public ResponseEntity<Object> findValidByEvent(@RequestParam(required = true,
      value = "activityId") Long activityId) {

    ResponseEntity<Object> responseEntity = null;

    try {
      List<ActivityCouponRule> list = activityCouponRuleManager.listByActivityId(activityId);

      Result<List<ActivityCouponRule>> result = new Result<List<ActivityCouponRule>>(0, "成功", list);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 根据优惠券规则id查询.
   * 
   * @param couponRuleId 优惠券规则id
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "findByCouponRuleId", method = RequestMethod.GET)
  public ResponseEntity<Object> findByCouponRuleId(@RequestParam(required = true,
      value = "couponRuleId") Long couponRuleId) {

    ResponseEntity<Object> responseEntity = null;

    try {
      List<ActivityCouponRule> list = activityCouponRuleManager.listByCouponRuleId(couponRuleId);

      Result<List<ActivityCouponRule>> result = new Result<List<ActivityCouponRule>>(0, "成功", list);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }


}
